﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 自引用的组织结构树;

namespace 自引用的组织结构树
{
    internal class MyDbContext : DbContext
    {
        public DbSet<OrgUnit> OrgUnits { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {

            string connStr = "Data Source=.;Initial Catalog=demo3;User ID=sa;Password=123456;TrustServerCertificate=True";
            optionsBuilder.UseSqlServer(connStr);
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            //从当前程序集(MyDbContext)加载所有的XXXConfig: IEntityTypeConfiguration<XXX>
            modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
        }
    }
}
